//
class SkillPrase{
    public constructor() {
	}
    private static _instance:SkillPrase;

    public static instance():SkillPrase{
		if(!SkillPrase._instance){
			SkillPrase._instance = new SkillPrase();
		}
		return SkillPrase._instance;
	}

    // 升级钓鱼数量
    public updateFishNumber(call:Function, scope){
        let openid = RoleCache.instance().openid ? RoleCache.instance().openid : '' ;
        let data = {
            openid : openid,
            type : 'count'
        }
        HttpManager.instance().sendPost(GameConst.httpUrl + 'fishingaccs/update_skill', StringUtil.jsonToHttpPostString(data) , (e)=>{
            let data = JSON.parse(e)

            if(data.msg == 'ok'){
                RoleCache.instance().data.money = data.data.money
                RoleCache.instance().data.count.next_pay = data.data.count.next_pay
                RoleCache.instance().data.count.num = data.data.count.num

                if(call){
                    call.call(scope, data.data);
                }
                GameUtil.dispatchEvent(EventConst.RESOURCE_CHANGED);
            }else{}
            
        } , this)
    }

    // 升级钓鱼深度
    public updateFishDepth(call:Function, scope){
        let openid = RoleCache.instance().openid ? RoleCache.instance().openid : '' ;
        let data = {
            openid : openid,
            type : 'depth'
        }
        HttpManager.instance().sendPost(GameConst.httpUrl + 'fishingaccs/update_skill', StringUtil.jsonToHttpPostString(data) , (e)=>{
            let data = JSON.parse(e)

            if(data.msg == 'ok'){
                RoleCache.instance().data.money = data.data.money
                RoleCache.instance().data.depth.next_pay = data.data.depth.next_pay
                RoleCache.instance().data.depth.num = data.data.depth.num
            
                if(call){
                    call.call(scope, data.data);
                }
                GameUtil.dispatchEvent(EventConst.RESOURCE_CHANGED);
            }else{
                
            }
            
        } , this)
    }

    // 升级离线收益
    public updateFishOffline(call:Function, scope){
        let openid = RoleCache.instance().openid ? RoleCache.instance().openid : '' ;
        let data = {
            openid : openid,
            type : 'offline'
        }
        HttpManager.instance().sendPost(GameConst.httpUrl + 'fishingaccs/update_skill', StringUtil.jsonToHttpPostString(data) , (e)=>{
            let data = JSON.parse(e)

            if(data.data)
            {
                RoleCache.instance().data.money = data.data.money
                RoleCache.instance().data.offline.next_pay = data.data.offline.next_pay
                RoleCache.instance().data.offline.num = data.data.offline.num

                if(data.msg == 'ok'){
                    if(call){
                        call.call(scope, data.data);
                    }
                    GameUtil.dispatchEvent(EventConst.RESOURCE_CHANGED);
                }else{
                    
                }
            }
            
        } , this)
    }

    //获取离线收益
    public getOfflineMoney(multiple){
        let openid = RoleCache.instance().openid ? RoleCache.instance().openid : '' ;
        let data = {
            openid : openid,
            multiple : multiple
        }
        HttpManager.instance().sendPost(GameConst.httpUrl + 'fishingaccs/update_offline_money', StringUtil.jsonToHttpPostString(data) , (e)=>{
            UIManager.instance().hideNormalLoading();
            MessageUtil.tips('领取成功');
            let data = JSON.parse(e)

            RoleCache.instance().data.money = data.data
            GameUtil.dispatchEvent(EventConst.RESOURCE_CHANGED);
            UIManager.instance().closeUILogic(UIConst.ACCOUNT_UI);
        } , this)
    }

    // 领取钓鱼收益
    public getFishMoney(arr , money , multiple){
        let openid = RoleCache.instance().openid ? RoleCache.instance().openid : '' ;
        let data = {
            collection : StringUtil.arrToHttpLineString(arr),
            openid : openid,
            money : money * multiple
        }
        UIManager.instance().showNormalLoading();
        HttpManager.instance().sendPost(GameConst.httpUrl + 'options/get_fished_data' , StringUtil.jsonToHttpPostString(data) , (e)=>{
            UIManager.instance().hideNormalLoading();
            // MessageUtil.tips('领取成功');
            let data = JSON.parse(e)

            if(data && data.data)
            {
                MessageUtil.tips('领取成功');
                RoleCache.instance().data.money = data.data.money;

                if(GuideManager.instance().judgeIsCompleteGuide(1,3))
                TujianCache.instance().setCurTujianList(data.data.new);
                
                GameUtil.dispatchEvent(EventConst.RESOURCE_CHANGED);

                let heightMaxScore = RoleCache.instance().heightMaxScore;
                let curMaxScore = data.data.max_score;
                if(curMaxScore > heightMaxScore)
                {
                    RankManager.instance().uploadUserScore(curMaxScore, 'money');
                    RoleCache.instance().setMaxScore(curMaxScore);
                }
            }

            UIManager.instance().closeUILogic(UIConst.ACCOUNT_UI);
        })

    }
}